package com.cs.user.domain.service.impl;

import com.cs.user.common.entity.BaseResponse;
import com.cs.user.common.entity.ErrorCode;
import com.cs.user.common.utlis.ThrowUtils;
import com.cs.user.domain.bos.UserRoleBO;
import com.cs.user.domain.service.UserRoleDomainService;
import com.cs.user.infra.basic.entity.UserRole;
import com.cs.user.infra.basic.service.UserRoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserRoleDomainServiceImpl implements UserRoleDomainService {

    @Resource
    private UserRoleService userRoleService;

    @Override
    public Boolean addUserRole(UserRoleBO userRoleBO) {
        // 参数校验
        ThrowUtils.throwIf(userRoleBO.getRoleId() == null, ErrorCode.PARAMS_ERROR, "怎么没有角色id！");
        ThrowUtils.throwIf(userRoleBO.getUserId() == null, ErrorCode.PARAMS_ERROR, "怎么没有用户id！");
        // 类型转换
        UserRole userRole = new UserRole();
        BeanUtils.copyProperties(userRoleBO, userRole);
        // 调用infra层方法
        return userRoleService.addUserRole(userRole);
    }
}
